<!--
* writer: 姜
* create date: 2018年6月30日
* rewriter:
* rewrite date:
* description:发布视频

 -->

<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>发布视频</title>
    <link rel="stylesheet" type="text/css" href="../../../css/base.css" />
</head>

<body>
    <div id="app">

    </div>
</body>

</html>
<script type="text/javascript" src="../../../script/api.js"></script>
<script type="text/javascript" src="../../../script/common.js"></script>
<script type="text/javascript" src="../../../script/vue.js"></script>
<script type="text/javascript">
    function shootReset() {
        var playModule = api.require('playModule');
        playModule.cleanPlayers(function(ret, err) {});
    }

    function setShootingStart(time) {
        var nowTime = time + 1
        var videoRecorder = api.require('videoRecorder');
        videoRecorder.start({
            timer: nowTime
        });
    }

    function shootingStop() {
        var videoRecorder = api.require('videoRecorder');
        videoRecorder.stop();
    }

    function shootingUp() {
        var edit = "videoUp('" + vm.videoPath + "');";
        send_event('shootingUp', {
          videoPath: vm.videoPath
        })
        // api.execScript({
        //     frameName: 'publish_now_f',
        //     script: edit
        // });
        closeWin();
    }
    var vm = new Vue({
        el: '#app',
        data: {
            videoPath: '', //视频路径
        },
        methods: {

            setinit: function() {
                api.openFrame({
                    name: 'publishing_video_shooting_main',
                    url: 'publishing_video_shooting_main.html',
                    bounces: false,
                    pageParam: {
                        time: api.pageParam.time,
                    },
                    rect: {
                        x: 0,
                        y: 0,
                        w: api.winWidth,
                        h: api.winHeight
                    }
                })
            },


            // 启动
            init: function() {
                var videoRecorder = api.require('videoRecorder');
                videoRecorder.open({
                    rect: {
                        x: 0,
                        y: 0,
                        w: api.frameWidth,
                        h: api.frameHeight
                    },
                    quality: "medium",
                    saveToAlbum: true,
                    save: {
                        path: 'fs://videoRecorder',
                        name: new Date().getTime()
                    },

                    fixed: false
                }, function(ret) {
                    if (ret) {
                        if (api.systemType == 'ios') {
                            vm.videoPath = ret.filePath
                        } else {
                            vm.videoPath = ret.albumPath
                        }
                    }
                    if (ret.filePath) {
                        var playModule = api.require('playModule');
                        playModule.play({
                            rect: {
                                x: 0,
                                y: 0,
                                w: api.frameWidth,
                                h: api.frameHeight
                            },
                            url: ret.filePath,
                            fixedOn: api.frameName,
                            defaultBtn: false,
                            enableFull: false,
                            isTopView: false,
                        }, function(ret, err) {
                            vm.setinit();
                        });
                    }
                });
            }
        }
    });
    apiready = function() {
        api.parseTapmode();
        var playModule = api.require('playModule');
        playModule.init({
            FullScreenViewIsFont: false,
        });
        vm.setinit();
        vm.init();
        api.addEventListener({
            name: 'keyback'
        }, function(ret, err) {
            return false
        });
    };
</script>
